<template>
	<view>
    <!-- 首页 start -->
      <home v-if="component == 'home'" ref="home" @barChange="barChange"></home>
      <!-- 首页 end -->
      <!-- 商品页 start -->
      <goods v-if="component == 'goods'" @barChange="barChange" ref="goods"></goods>
      <!-- 商品页 end -->
      <!-- 商品分页 start -->
      <cate v-if="component == 'cate'" @barChange="barChange"></cate>
      <!-- 商品分页 end -->

      <!--    断网监测 start-->
      <fu-notwork></fu-notwork>
      <!--    断网监测 end-->
      <!-- tabbar start -->
      <!-- <bar @change="change" ref="bar"></bar> -->
      <!-- tabbar end -->


	</view>
</template>

<script>
  // 引入首页
  import home from './home.vue';
  // 引入商品页
  import goods from './goods.vue';
  // 引入分类页
  import cate from './cate.vue';
  //
  import bar from './bar.vue';

	export default {
    components:{
      home,
      goods,
      cate,
      bar,
    },
		data() {
			return {
        component:'home',
        shopInfo:null,
			}
		},
		computed: {
			location() {
				return this.$store.getters.location;
			}
		},
    onLoad(options) {
      // partner_id 店铺id  76测试店铺id
      // let {partner_id = 76} = options;
	  console.log("options",options)
      this.$store.commit('partner_id',options.partner_id);
      this.get_shop_info(options.partner_id);
    },
    onShow(){
      console.log(this.component)
      if(this.component == 'customer'){
        this.component = 'home'
        this.barChange('home')
      }
    },
		methods: {
      /**
       * @description 接收bar参数切换组件
       * @param {String} component 组件名称
       */
      change(component){
        console.log(component)
        this.component = component;
        // 跳转客服页面
        if(component == 'customer'){
          console.log(this.shopInfo,999)
           this.$util.actionAuth(() => {
             this.$urouter.navigateTo({
               url: '/pages/service-message/service/service-detail/index',
               params: {
                kid: this.shopInfo.member_id,
                partner_id: this.shopInfo.member_id,
                goods_id: this.goods_id,
                activity_id: this.activity_id || 0
               }
             });
           });
          // this.component = 'home';
        }
      },
      /**
       * @description 子传父
       * @param {String} type == component
       */
      barChange(type){
        console.log(type)
        this.$refs.bar.handleTarbar(type);
      },
      /**
       * @description 获取店铺信息
       */
      get_shop_info(partner_id){
		console.log(partner_id,"partner_id")
        this.$api
          .post(global.apiUrls.get_shop_info, {
            partner_id: partner_id,//店铺id,
            user_id: (global.userInfo && global.userInfo.id) ||  0,
			lat: this.location.latitude,
			lng: this.location.longitude
          })
          .then(res => {
            console.log('店铺信息',res);
            if (res.data.code == 1) {
              this.shopInfo = res.data.data
              this.$store.commit('shopInfo',res.data.data);
            }else{
              this.$message.info(res.data.msg);
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
		},
    /**
     * @description 率先你
     */
    onPullDownRefresh() {
      if(this.component == 'home' || this.component == 'goods'){
        // home不带关键词搜索
        this.$refs[this.component].refresh();
      }else{
        uni.stopPullDownRefresh();
      }
    },
    /**
     * @description 上拉加载
     */
    onReachBottom() {
      if(this.component == 'home' || this.component == 'goods'){
        // home不带关键词搜索
        this.$refs[this.component].getGoodsGetGoodsList();
      }

    },
    /**
     * @description 页面滚动
     */
    onPageScroll(e) {
      if(this.component == 'home' || this.component == 'goods'){
        if(e.scrollTop > 500){
          this.$refs[this.component].scrollShow(true);
        }else{
          this.$refs[this.component].scrollShow(false);
        }
      }
    }
	}
</script>

<style scoped lang="scss">

</style>
